package cn.tedu.wms.product.controller;

import cn.tedu.wms.product.pojo.dto.StockDTO;
import cn.tedu.wms.product.pojo.vo.StockListVO;
import cn.tedu.wms.product.pojo.vo.StockStandardVO;
import cn.tedu.wms.product.service.StockService;
import cn.tedu.wms.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "03.库存管理模块")
@RequestMapping("/stock")
public class StockController {

    @Autowired
    StockService stockService;

    public StockController() {
        System.out.println("创建控制器类对象：StockController");
    }

    @PostMapping("/add")
    @ApiOperation("添加库存")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(StockDTO stockDTO){
        log.debug("开始处理【添加库存】的请求，参数：{}", stockDTO);
        stockService.addNew(stockDTO);
        return JsonResult.ok();
    }

    @ApiImplicitParam(name = "id", value = "库存id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除库存")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(Long id){
        log.debug("开始处理【添加库存】的请求，参数：{}", id);
        stockService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("查询库存详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "库存id", required = true, dataType = "long")
    @GetMapping ("/{id:[0-9]+}/delete")
    public JsonResult<StockStandardVO> getStandard(Long id) {
        log.debug("开始处理【查询库存详情】的请求");
        StockStandardVO standard = stockService.getStandard(id);
        return JsonResult.ok(standard);
    }

    @ApiOperation("查询库存列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<StockListVO>> list() {
        log.debug("开始处理【查询库存列表】的请求");
        List<StockListVO> list = stockService.list();
        return JsonResult.ok(list);
    }

}
